//
//  TextViewController.m
//  random-name-generator
//
//  Created by eewert on 10/17/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TextViewController.h"

@implementation TextViewController

@synthesize descriptionLabel;
@synthesize nameLabel;
@synthesize backButton;
@synthesize restartButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NameTypeSelectionViewController *parent = (NameTypeSelectionViewController *)self.parentViewController;
    UserInputViewController *grandparent = (UserInputViewController *)parent.parentViewController;
    NSString *lang = [parent.languages objectAtIndex:[parent.picker selectedRowInComponent:0]];
    
    NSString *safeLang = lang;
    if([lang caseInsensitiveCompare:@"Pornstar"] == NSOrderedSame)
    {
        @try {
            NSInteger age = [grandparent.ageField.text integerValue];
            if(age < 18)
            {
                safeLang = @"Jailbait";
            }
        }
        @catch (NSException * e) {
            // You're over age, or you mashed ASDFGSDJHKFGKDSJFGHL, so whatever
        }
    }
    
    descriptionLabel.text = [[@"Your " stringByAppendingString:safeLang] stringByAppendingString:@" name is..."];
    
    UserInputViewController *uiVC = (UserInputViewController *)self.parentViewController.parentViewController;
    nameLabel.text = [uiVC getNameForLanguage:lang];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(IBAction)backButtonPress {
    //nameLabel.text = @"Back pressed";
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

-(IBAction)restartButtonPress {
    //nameLabel.text = @"Restart pressed";
    [self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
}

@end
